//
//  XFYOrderWebViewController.swift
//  幸福互联
//
//  Created by apple on 2017/5/15.
//  Copyright © 2017年 youjindi. All rights reserved.
//

import UIKit
import WebKit
import ReactiveCocoa
import ReactiveSwift

class WebViewController: UIViewController {
    
    private var URLString = String()
    var idString = String()

    init(URLString: String) {
        super.init(nibName: nil, bundle: nil)
        self.URLString = URLString
        layoutNews()
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(URLString: String,_ id: String){
        super.init(nibName: nil, bundle: nil)
        self.URLString = URLString
        self.idString = id
        layout()
        binding()
    }
    
    let webView = WKWebView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    let rightBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    private func layoutNews() -> Void {
        view.backgroundColor = UIColor.white
        let url = NSURL(string: URLString)
        let request = NSURLRequest(url: url! as URL)
        webView.load(request as URLRequest)
        webView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)
        view.addSubview(webView)
        
        
        rightBtn.setImage(UIImage(named:"未收藏"), for: .normal)
        let rightItem = UIBarButtonItem(customView: rightBtn)
        self.navigationItem.rightBarButtonItem = rightItem

        rightBtn.reactive.controlEvents(.touchUpInside).observeValues { (btn) in
            
        }
           
    }
    
    private func layout() -> Void {
        view.backgroundColor = UIColor.white
        let url = NSURL(string: URLString)
        let request = NSURLRequest(url: url! as URL)
        webView.load(request as URLRequest)
        webView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight-54)
        view.addSubview(webView)
        
        let btn = UIButton(frame: CGRect(x: 10, y: ScreenHeight - 50, width: ScreenWidth - 20, height: 44))
        btn.setTitle("拨打电话", for: .normal)
        btn.backgroundColor = MainColor
        
        btn.reactive.controlEvents(.touchUpInside).observeValues { (btn) in
            let allString = "tel:" + self.idString
            UIApplication.shared.openURL(URL(string:allString)!)
        }
        
        view.addSubview(btn)
    }
    
    
    //MARK: collecion
   
    
    private func binding(){
    
        
    }

}



